<template>
  <ul class="tab-bar">
    <li
      is="router-link"
      tag="li"
      v-for="nav in navs"
      :key="nav.path"
      :to="nav.path"
      :replace="nav.replace"
    >
      <i class="iconfont" v-html="nav.icon"></i>
      <span>{{ nav.title }}</span>
    </li>
  </ul>
</template>

<script>
import routes from '@/router/routes'

export default {
  name: 'TabBar',
  computed: {
    navs() {
      return (
        routes
          .filter(route => route.meta.inTabBar)
          .map(({ path, meta: { title, icon, replace } }) => ({
            path,
            title,
            icon,
            replace,
          }))
      )
    },
  },
}
</script>

// scoped 是保证所书写的样式仅在当前组件
// 中有作用，在其它组件中无效。
// 实现的原理是在组件的布局节点上添加自定义
// 的 data-v-xxx 属性，使用过 [data-v-xxx]
// 属性的节点添加样式，未使用过的则没有CSS效果
<style lang="less" scoped>
  @font-face {
    font-family: 'iconfont';  /* Project id 2878103 */
    src: url('http://at.alicdn.com/t/font_2878103_6ssrb9v2nvr.woff2?t=1634629438591') format('woff2'),
        url('http://at.alicdn.com/t/font_2878103_6ssrb9v2nvr.woff?t=1634629438591') format('woff'),
        url('http://at.alicdn.com/t/font_2878103_6ssrb9v2nvr.ttf?t=1634629438591') format('truetype');
  }

  .iconfont{
    font-family:"iconfont" !important;
    font-size:24px;font-style:normal;
    -webkit-font-smoothing: antialiased;
    -webkit-text-stroke-width: 0.2px;
    -moz-osx-font-smoothing: grayscale;
  }

  .tab-bar {
    display: flex;
    height: 64px;
    border-top: 1px solid #ccc;

    li {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
  }

  .router-link-exact-active, .router-link-active {
    color: #d81e06;
  }
</style>
